/**
 * 
 */
package net.microlinktech.testing.ui.celleditor;

import java.awt.Component;
import java.awt.event.MouseEvent;
import java.util.EventObject;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableCellEditor;

/**
 * @author zhangqing
 *
 */
public class TextFieldEditor extends AbstractCellEditor implements TableCellEditor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6390877520407926762L;
	final JTextField textField;
	
	public TextFieldEditor(){
		textField = new JTextField();
	}

	public java.awt.Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
			int row, int column) {
		textField.setText(value.toString());
		return textField;
	}

	public boolean isCellEditable(EventObject evt) {
		if (evt instanceof MouseEvent) {
			return ((MouseEvent) evt).getClickCount() >= 2;
		}
		return true;
	}

	public Object getCellEditorValue() {
		return textField.getText();
	}

}
